import React, { useState } from 'react';
import { View, Textarea, Button } from '@tarojs/components';
import './index.scss';

export default function Index() {
  const [content, setContent] = useState('');
  
  // 获取当前日期
  const getCurrentDate = () => {
    const now = new Date();
    const year = now.getFullYear();
    const month = now.getMonth() + 1;
    const day = now.getDate();
    const weekdays = ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'];
    const weekday = weekdays[now.getDay()];
    
    return `${year}年${month}月${day}日 ${weekday}`;
  };

  const handleSave = () => {
    if (!content.trim()) {
      console.log('请输入日记内容');
      return;
    }
    
    // 这里可以调用保存接口
    console.log('保存日记:', { content, date: new Date().toISOString() });
    
    // 清空内容
    setContent('');
  };

  return (
    <View className="diary-page">
      <View className="header">
        <View className="title">写日记</View>
        <View className="date">{getCurrentDate()}</View>
      </View>
      
      <View className="editor">
        <Textarea
          className="content-input"
          placeholder="记录今天的美好时光..."
          value={content}
          onInput={(e) => setContent(e.detail.value)}
          autoHeight={false}
          showConfirmBar={false}
        />
      </View>
      
      <View className="actions">
        <Button className="save-btn" onClick={handleSave}>
          保存日记
        </Button>
      </View>
    </View>
  );
} 